package com.greenold.refunds.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.greenold.refunds.domain.RefundDto;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.greenold.common.annotation.Log;
import com.greenold.common.core.controller.BaseController;
import com.greenold.common.core.domain.AjaxResult;
import com.greenold.common.enums.BusinessType;
import com.greenold.refunds.domain.Refund;
import com.greenold.refunds.service.IRefundService;
import com.greenold.common.utils.poi.ExcelUtil;
import com.greenold.common.core.page.TableDataInfo;

/**
 * 退款记录Controller
 * 
 * @author ruoyi
 * @date 2025-10-14
 */
@RestController
@RequestMapping("/greenold-refunds/refunds")
public class RefundController extends BaseController
{
    @Autowired
    private IRefundService refundService;

    /**
     * 查询退款记录列表
     */
    @PreAuthorize("@ss.hasPermi('greenold-refunds:refunds:list')")
    @GetMapping("/list")
//    public TableDataInfo list(Refund refund)
    public TableDataInfo list(RefundDto refundDto)
    {
        startPage();
//        List<Refund> list = refundService.selectRefundList(refund);
        List<RefundDto> list = refundService.selectRefundListAll(refundDto);
        System.out.println("数据根源"+list);
        return getDataTable(list);
    }

    /**
     * 导出退款记录列表
     */
    @PreAuthorize("@ss.hasPermi('greenold-refunds:refunds:export')")
    @Log(title = "退款记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Refund refund)
    {
        List<Refund> list = refundService.selectRefundList(refund);
        ExcelUtil<Refund> util = new ExcelUtil<Refund>(Refund.class);
        util.exportExcel(response, list, "退款记录数据");
    }

    /**
     * 获取退款记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('greenold-refunds:refunds:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(refundService.selectRefundById(id));
    }

    /**
     * 新增退款记录
     */
    @PreAuthorize("@ss.hasPermi('greenold-refunds:refunds:add')")
    @Log(title = "退款记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Refund refund)
    {
        return toAjax(refundService.insertRefund(refund));
    }

    /**
     * 修改退款记录
     */
    @PreAuthorize("@ss.hasPermi('greenold-refunds:refunds:edit')")
    @Log(title = "退款记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Refund refund)
    {
        return toAjax(refundService.updateRefund(refund));
    }

    /**
     * 删除退款记录
     */
    @PreAuthorize("@ss.hasPermi('greenold-refunds:refunds:remove')")
    @Log(title = "退款记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(refundService.deleteRefundByIds(ids));
    }


    @PostMapping("/apply")
    public AjaxResult applyRefund(@RequestBody Refund refund) {
        return refundService.applyRefund(refund);
    }

}
